package Enum;

public enum TestEnum {
    RED("红色",0),BLACK("黑色",1),
    GREEN("绿色",2),WHITE("白色",3);//枚举对象

    public String color;
    public int ordinal;

    //提供构造方法
    private TestEnum(String color, int ordinal) {
        this.color = color;
        this.ordinal = ordinal;
    }

    public static void main(String[] args) {
        TestEnum[] testEnums = TestEnum.values();
        for (TestEnum testEnum : testEnums) {
            System.out.println(testEnum);
        }

        for(int i=0;i<testEnums.length;i++){
            System.out.println(testEnums[i].ordinal());
        }

        /*
        System.out.println("=========");
        TestEnum val=TestEnum.valueOf("RED2");
        System.out.println(val);*/

        //比较两个枚举成员在定义时的顺序,前一个更靠前返回负数，靠后返回正数
        System.out.println(BLACK.compareTo(WHITE));
    }

    public static void main1(String[] args) {
        TestEnum testEnum=RED;
        switch(testEnum) {
            case BLACK:
                System.out.println("BLACK");
                break;
            case RED:
                System.out.println("RED");
                break;
            case GREEN:
                System.out.println("GREEN");
                break;
            default:
                System.out.println("颜色错误！");
                break;
        }
    }
}
